home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15390 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  69 lines

  1. Path: newsbf02.news.aol.com!not-for-mail
  2. From: theoder@aol.com (The Oder)
  3. Newsgroups: comp.lang.c
  4. Subject: A real basic problem?:  (code!) long integers or compiler problem?
  5. Date: 18 Apr 1996 16:39:26 -0400
  6. Organization: America Online, Inc. (1-800-827-6364)
  7. Sender: root@newsbf02.news.aol.com
  8. Message-ID: <4l699u$cgo@newsbf02.news.aol.com>
  9. References: <4l3mom$f26@newsbf02.news.aol.com>
  10. Reply-To: theoder@aol.com (The Oder)
  11. NNTP-Posting-Host: newsbf02.mail.aol.com
  12.  
  13. Repost of original problem:  (code to follow)
  14.  
  15. I'm in the process of relearning C and have been doing some beginning
  16. programs on my PC.  I have two compilers (Borland C++ and Power C).  My
  17. problem is that when I run a program using "long" integers (i.e. declare a
  18. variable as "long"), it locks up immediately and I have to reboot.  This
  19. has happened with both compilers and with two different really basic
  20. programs (i.e. just trying to do a loop that will compute the first 10
  21. powers of 2, and another one that simply just tries to find the largest
  22. positive long value on my computer--> I can find the largest positive int
  23. value, but when I convert it to long, it locks up)
  24.  
  25. Is this a problem I have with BOTH (?!?!) compilers, is it my computer
  26. (486-DX2, 8 megs RAM) or settings, or is it just something I haven't
  27. learned yet about long integers?  One of these programs I copied directly
  28. from one of TWO books I'm using and it just locks up!
  29.  
  30.  
  31. Here's the code: (for the program that will return the largest positive
  32. long value on my machine)
  33.  
  34. #include <stdio.h>
  35. #include "local.h"
  36.  
  37. void main()
  38. {
  39. long i;
  40. long maxlng();
  41.  
  42. i=maxlng();
  43. printf("max i= %d,  max i+1= %d",i,i+1);
  44. }
  45.  
  46. long maxlng()
  47. {
  48.  
  49. long first, b;
  50.  
  51. first= 10000;
  52. while (first >= 0)
  53. {
  54. b= first;
  55. printf("b= %d,  first= %d\n",b, first);
  56. first++;
  57. }
  58. return (b);
  59. }
  60.  
  61.  
  62. Whether I change the %d to %ld, does not make any difference.  If I put
  63. some printf statements in my loop, "first" is negative (!) sometimes
  64. during this loop even though the "while" statement is only supposed to
  65. work if "first" is positive!  
  66.  
  67. Thanks once again!
  68.  
  69.